home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Application: HideMenuBar */
- /* */
- /* Description: This snippet shows how to hide the menu bar by simply */
- /* creating a window with a visRgn that includes the */
- /* entire main screen's gray region and its menu bar. */
- /* */
- /* Files: HideMenuBar.π */
- /* HideMenuBar.c */
- /* */
- /* Programmer: Edgar Lee */
- /* Organization: Apple Computer, Inc. */
- /* Department: Developer Technical Support, DTS */
- /* Language: C (Think C version 5.0.2) */
- /* Date Created: 09-22-92 */
- /* */
- /****************************************************************************/
-
- /* Global Variable Definitions */
-
- WindowPtr gWindow;
-
- void initMac();
-
- void HideMenuBar();
- void HideIt();
- void drawWindow();
- void doEventLoop();
-
- main()
- {
- initMac();
-
- HideMenuBar();
-
- doEventLoop();
- }
-
- void initMac()
- {
- MaxApplZone();
-
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- FlushEvents( 0, everyEvent );
- }
-
- void HideMenuBar()
- {
- Rect rect;
-
- gWindow = NewCWindow( 0L, &rect, "\p", false, plainDBox,
- (WindowPtr)-1L, true, 0L );
-
- MoveWindow( gWindow, qd.screenBits.bounds.left, qd.screenBits.bounds.top, true );
- SizeWindow( gWindow, qd.screenBits.bounds.right - qd.screenBits.bounds.left,
- qd.screenBits.bounds.bottom - qd.screenBits.bounds.top, false );
-
- SetPort( gWindow );
- ShowWindow( gWindow );
-
- TextMode( geneva );
- TextSize( 9 );
- TextMode( srcXor );
- }
-
- void HideIt()
- {
- /****************************************************/
- /* Set the window's visRgn to include the menu bar. */
- /****************************************************/
-
- RectRgn( (*gWindow).visRgn, &qd.screenBits.bounds );
- InvalRect( &qd.screenBits.bounds );
-
- /*************************************************/
- /* Set the global MBarHeight to 0 to prevent any */
- /* other apps from writing to the menu bar. */
- /*************************************************/
-
- *((short *)0xbaa) = 0;
- }
-
- void drawWindow()
- {
- ForeColor( redColor );
- PaintRect( &qd.screenBits.bounds );
-
- MoveTo( 15, 15 );
- DrawString( "\pPress any key to quit." );
- }
-
- void doEventLoop()
- {
- EventRecord event;
- WindowPtr window;
- short clickArea;
- Rect screenRect;
-
- for (;;)
- {
- if (WaitNextEvent( everyEvent, &event, 0, nil ))
- {
- if (event.what == mouseDown)
- {
- clickArea = FindWindow( event.where, &window );
-
- if (clickArea == inDrag)
- {
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow( window, event.where, &screenRect );
- }
- else if (clickArea == inContent)
- {
- if (window != FrontWindow())
- SelectWindow( window );
- }
- else if (clickArea == inGoAway)
- if (TrackGoAway( window, event.where ))
- return;
- }
- else if (event.what == keyDown || event.what == autoKey)
- ExitToShell();
- else if (event.what == updateEvt)
- {
- window = (WindowPtr)event.message;
- SetPort( window );
-
- BeginUpdate( window );
- drawWindow();
- EndUpdate( window );
- }
- else if (event.what == activateEvt)
- {
- HideIt();
- }
- }
- }
- }